/*
 * @Author: xws 1043495328@qq.com
 * @Date: 2023-07-24 15:42:44
 * @LastEditors: xws 1043495328@qq.com
 * @LastEditTime: 2023-07-24 16:54:29
 * @FilePath: \vue3-admin-template\src\store\modules\category.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// 商品分类全局组件小仓库
import { defineStore } from 'pinia'
import { reqC1, reqC2, reqC3 } from '@/api/product/attr'
import type { CategoryResponseData } from '@/api/product/attr/type'
import type { CategoryState } from './types/type'
const useCategoryStore = defineStore('Category', {
  state: (): CategoryState => {
    return {
      //存储一级分类的数据
      c1Arr: [],
      c2Arr: [],
      c3Arr: [],
      c3Id: '',
      c1Id: '',
      c2Id: '',
    }
  },
  actions: {
    //获取一级分类的方法
    async getC1() {
      //发请求获取一级分类的数据
      const result: CategoryResponseData = await reqC1()
      //   console.log('result: ', result)
      if (result.code == 200) {
        this.c1Arr = result.data
      }
    },
    async getC2() {
      // 获取二级分类的数据
      const result: CategoryResponseData = await reqC2(this.c1Id)
      // console.log('result: ', result);
      if (result.code == 200) {
        this.c2Arr = result.data
      }
    },
    async getC3() {
      // 获取二级分类的数据
      const result: CategoryResponseData = await reqC3(this.c2Id)
      // console.log('result: ', result);
      if (result.code == 200) {
        this.c3Arr = result.data
      }
    },
  },
  getters: {},
})
export default useCategoryStore
